﻿namespace Hotel.Web.Models
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using Hotel.Model.Infrastructure;
    using HotelResourses = Hotel.Module.Resources.Models;

    public class Service : IAssignable
    {

        public static Service FromDomainModel(Hotel.Module.Resources.Models.Service domainService)
        {
            Service model = new Service();
            model.Name = domainService.Name;
            model.Price = domainService.Cost;
            model.State = domainService.Rated;
            model.ID = domainService.ID;
            return model;
        }

        public void AssignTo(object obj)
        {
            if (obj is HotelResourses.Service)
            {
                HotelResourses.Service domainService = obj as HotelResourses.Service;

                domainService.Name = this.Name;
                domainService.Cost = this.Price;
                domainService.Rated = this.State;
                domainService.ID = this.ID;
                return;
            }
            //else
            throw new NotSupportedException();
        }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.Assignment.AssignmentResources), Name = "ServiceName")]
        public string Name { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.Assignment.AssignmentResources), Name = "ServicePrice")]
        public double Price { get; set; }

        [Display(ResourceType = typeof(Hotel.Web.Views.Assignment.AssignmentResources), Name = "ServiceState")]
        public bool State { get; set; }

        public int ID { get; set; }
    }
}